<!--计量单位选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" :title="modalTitle" width="960px" destroyOnClose
      v-model:visible="visible">
      <!--引用表格-->
      <BasicTable @register="registerTable" :rowSelection="rowSelection">
        <!--插槽:搜索-->
        <template #form-billType="{ model, field }">
          <a-input-search v-model:value="model[field]" placeholder="请选择单据类型" readonly @search="openBillType" />
        </template>
        <!--插槽:table标题-->
        <!-- <template #tableTitle>
          <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增
          </a-button>
        </template> -->
        <!--操作栏-->
      </BasicTable>
      <template #footer>
        <a-button @click="close">关闭</a-button>
        <a-button @click="handleSubmit" type="primary">确认</a-button>
      </template>
    </BasicModal>
  <!-- 单据类型 -->
  <billTypeSelectModel @register="billTypeRegModal" @getSelectResult="billTypeHandleSuccess" v-bind="getBindValue"></billTypeSelectModel>
  </div>
</template>
<script lang="ts">
  import {
    BasicForm
  } from '/@/components/Form/index';
  import {
    defineComponent,
    ref,
    unref,
    reactive,
    toRaw
  } from 'vue';
  import {
    BasicModal,useModal
  } from '/@/components/Modal';
  import {
    createAsyncComponent
  } from '/@/utils/factory/createAsyncComponent';
  import {
    useSelectBiz
  } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
  import {
    selectProps
  } from '/@/components/Form/src/jeecg/props/props';
  import {
    useAttrs
  } from '/@/hooks/core/useAttrs';
  import {
    render
  } from '/@/utils/common/renderUtils';
  import {
    useListPage
  } from '/@/hooks/system/useListPage'
  import {
    searchFormSchema,
    psProductionPlanMpsItemColumns,
    columns,
    orderColumns
  } from "../PsProductionPlanMps.data";
  import {
    getOrderCenterList
  } from '../PsProductionPlanMps.api';
  import billTypeSelectModel from '/@/views/components/billTypeSelectModel.vue';

    
  export default defineComponent({
    name: 'MpsSelectModel',
    components: {
      //此处需要异步加载BasicTable
      BasicModal,
      useModal,
      BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
        loading: true,
      }),
    },
    props: {
      ...selectProps,
      //选择框标题
      modalTitle: {
        type: String,
        default: '筛选条件',
      },
    },

    emits: ['getSelectResult'],
    setup(props, {
      emit
    }) {
      //表单modal
      const planModel = reactive({});
      //注册table数据
      const {
        tableContext
      } = useListPage({
        tableProps: {
          title: '订单中心',
          api: getOrderCenterList,
          columns: orderColumns,
          canResize: false,
          formConfig: {
            labelWidth: 100,
            schemas: searchFormSchema, 
            autoSubmitOnEnter: true,
            showAdvancedButton: true,
            fieldMapToNumber: [],
            fieldMapToTime: [],
          },
          showActionColumn: false,
          // 请求之前对参数做处理
          beforeFetch(params) {
            params.billStatus = 0;
            params.productionPlanQuery = 1;
          },
        },
      })

      const [registerTable, {
        reload,getSelectRows
      }, {
        rowSelection,
      }] = tableContext;
      //弹窗显隐
      const visible = ref(false);
      /**
       * 确定选择
       */
      function handleSubmit() {
        emit("getSelectResult",getSelectRows());
        close();
      }

      function close() {
        visible.value = false;
      }

      const [billTypeRegModal, { openModal: openBillTypeModal }] = useModal();
      //打开选择单据类型
      function openBillType() {
      console.log("123");
      
      openBillTypeModal(true, {
          isUpdate: false,
          showFooter: true,
      });
      }
      function billTypeHandleSuccess(val) { 
        console.log("VAL",val);
        
      }
      return {
        visible,
        close,
        handleSubmit,
        planModel,
        registerTable,
        rowSelection,
        openBillType,
        billTypeHandleSuccess
      };
    },
  });

</script>
